package com.example.as_sum.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.example.as_sum.R;

import java.util.List;

/**
 * Created by ran on 2016/8/1.
 */
public class MyAdapter extends BaseAdapter {
    private List<String> list;
    private Context mContext;
    public MyAdapter(Context mContext,List<String> list){
        this.list=list;
        this.mContext=mContext;
    }
    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHodler hodler=null;
        if(convertView == null){
            convertView= LayoutInflater.from(mContext).inflate(R.layout.item_layout,parent,false);
            hodler=new ViewHodler();
            hodler.tv=(TextView)convertView.findViewById(R.id.item_layout_text);
            convertView.setTag(hodler);
        }else{
            hodler=(ViewHodler)convertView.getTag();
        }
        hodler.tv.setText(getItem(position).toString());
        return convertView;
    }
    class ViewHodler{
        TextView tv;
    }
}
